package com.ssm.entity;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.List;
/*
* 封装分页查询*/
@Getter
@Setter
@ToString
public class PageResult<T> {
    //接收用户的请求
    private int currentPage;//当前页
    private int pageSize;//每页显示的长度

    //两个数据库查询的
    private int totalCount;//总条数
    private List<T> date;//每页显示的数据

    //第二个要计算的
    private int prevPage;//上一页
    private int nextPage;//下一页
    private int totalPage;//总页数

    public PageResult(int currentPage, int pageSize, int totalCount, List<T> date) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.date = date;
        //计算总页数
        this.totalPage = this.totalCount % this.pageSize == 0 ?
                this.totalCount / this.pageSize : this.totalCount / this.pageSize + 1;
        //计算上一页
        this.prevPage = this.currentPage - 1 > 1 ? this.currentPage - 1 : 1;
        //计算下一页
        this.nextPage = this.currentPage + 1 <= this.totalPage ? this.currentPage + 1 : this.totalPage;
    }
}
